<?php

/**
 * 保证金管理
 */
namespace app\avikcm\controller;
use think\Db;
use think\facade\Request;

class Deposit extends Common
{
    public function initialize()
    {
        parent::initialize();
    }

    /** 
     * 保证金列表 
     */
    public function index(){
        if(Request::isAjax()){
            $key = input('post.key');
            $this->assign('testkey', $key);
            $map[] = ['a.order_status','=',2];
            if($key){
                $map[] = ['a.order_id|c.nickname','like','%'.$key.'%'];
            }
            $page =input('page')?input('page'):1;
            $pageSize =input('limit')?input('limit'):config('pageSize');
            $list = Db::table('spot_order_info')->alias('a')
                ->join('goods_info b', 'a.gid = b.id', 'left')
                ->join('users c', 'a.uid = c.id', 'left')
                ->field('a.id, a.order_id, a.uid, a.order_price, a.buy_deposit,a.pay_time, b.name, c.mobile,c.nickname')
                ->where($map)
                ->order('a.pay_time DESC')
                ->paginate(array('list_rows'=>$pageSize,'page'=>$page))
                ->toArray();
            return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
        }
        return $this->fetch('index');
    }

    public function info(){
        $id=input('id');
        $info = Db::table('spot_order_info')->alias('a')
                ->join('goods_info b', 'a.gid = b.id', 'left')
                ->join('users c', 'a.uid = c.id', 'left')
                ->field('a.*, b.name,b.content, c.mobile,c.nickname')
                ->where('a.id', $id)
                ->find();

        $this->assign('info',json_encode($info,true));
        $this->assign('title','查看详情');
        return $this->fetch('form');
    }

}